/**
 * 
 */
package hr.fer.zemris.annotator.model;

import hr.fer.zemris.annotator.model.profiling.CallGraphData;
import hr.fer.zemris.annotator.model.profiling.MethodMappingData;

import java.util.List;

/**
 * @author dajan
 * 
 */
public class MethodData {

	private List<Method> methodFlatData;
	private List<CallGraphData> callGraphData;
	private List<MethodMappingData> methodMappingData;

	public MethodData(List<Method> methodFlatData,
			List<CallGraphData> callGraphData,
			List<MethodMappingData> methodMappingData) {
		super();
		this.methodFlatData = methodFlatData;
		this.callGraphData = callGraphData;
		this.methodMappingData = methodMappingData;
	}

	public List<Method> getMethodFlatData() {
		return methodFlatData;
	}

	public void setMethodFlatData(List<Method> methodFlatData) {
		this.methodFlatData = methodFlatData;
	}

	public List<CallGraphData> getCallGraphData() {
		return callGraphData;
	}

	public void setCallGraphData(List<CallGraphData> callGraphData) {
		this.callGraphData = callGraphData;
	}

	public List<MethodMappingData> getMethodMappingData() {
		return methodMappingData;
	}

	public void setMethodMappingData(List<MethodMappingData> methodMappingData) {
		this.methodMappingData = methodMappingData;
	}

	public String toString(Method method) {

		String flatProfileData = method.getProfileData().toString();
		String methodIndex = "";
		String callGraphData = "";

		for (MethodMappingData mapping : methodMappingData) {
			if (method.getMethodName().equals(mapping.getMethodName())) {
				methodIndex = mapping.getIndex();
				break;
			}
		}

		for (CallGraphData cgd : this.callGraphData) {
			if (cgd.isIndex(methodIndex)) {
				callGraphData = cgd.toString();
			}
		}

		callGraphData = "Call graph data for this function: "
				+ System.getProperty("line.separator")
				+ "---------------------------------------------"
				+ System.getProperty("line.separator")
				+ "index % time    self  children    called     name"
				+ System.getProperty("line.separator")
				+ callGraphData.replace("#",
						System.getProperty("line.separator"));

		String finalString = "/*" + System.getProperty("line.separator");
		finalString += flatProfileData;
		finalString += System.getProperty("line.separator");
		finalString += System.getProperty("line.separator");
		finalString += callGraphData;
		finalString += System.getProperty("line.separator");
		finalString += "*/";
		finalString += System.getProperty("line.separator");

		return finalString;
	}

}
